package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.core.BmsBatchDao;
import com.tbit.main.exception.BaseException;
import com.tbit.main.pojo.BmsBatch;
import com.tbit.main.service.BmsBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LMY
 * @create 2022-07-14 17:33
 */
@Service("bmsBatchService")
public class BmsBatchServiceImpl implements BmsBatchService {

    @Autowired
    private BmsBatchDao bmsBatchDao;

    @Override
    public BmsBatch getAccountIdBatchName(Integer accountId, String batchName) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, accountId);
        map.put("batchName", batchName);
        return bmsBatchDao.getAccountIdBatchName(map);
    }

    @Override
    public void insert(BmsBatch bmsBatch) {
        bmsBatchDao.insert(bmsBatch);
    }

    @Override
    public List<BmsBatch> getAccountId(Integer accountId) {
        return bmsBatchDao.getAccountId(accountId);
    }

    @Override
    public void del(Integer batch) {
        bmsBatchDao.del(batch);
    }

    @Override
    public List<BmsBatch> getAll() {
        return bmsBatchDao.getAll();
    }

    @Override
    public BmsBatch getBmsBatch(Integer batch) {
        BmsBatch bmsBatch = bmsBatchDao.getBmsBatch(batch);
        if (bmsBatch == null) {
            throw new BaseException("batch.ter.notExit");
        }
        return bmsBatch;
    }

    @Override
    public void update(BmsBatch bmsBatch) {
        bmsBatchDao.update(bmsBatch);
    }
}
